using System;
using System.Collections.Generic;
using Holoville.HOTween;
using UnityEngine;

[RequireComponent(typeof(tk2dUIItem))]
public class tk2dUIColorUpDown : MonoBehaviour
{
	public Color UpColor
	{
		get
		{
			return this.upColor;
		}
		set
		{
			this.upColor = value;
		}
	}

	private void Start()
	{
		this.SetColor(false);
	}

	private void OnChangeTheme()
	{
		this.SetColor(true);
	}

	private void SetColor(bool isChangeTheme = false)
	{
		if (this.buttonSprite != null)
		{
			this.target = this.buttonSprite.gameObject;
		}
		if (this.target == null)
		{
			this.target = base.gameObject;
		}
		tk2dBaseSprite[] array;
		tk2dTextMesh[] array2;
		TextMesh[] array3;
		if (this.isChildTween)
		{
			array = this.target.GetComponentsInChildren<tk2dBaseSprite>(true);
			array2 = this.target.GetComponentsInChildren<tk2dTextMesh>(true);
			array3 = this.target.GetComponentsInChildren<TextMesh>(true);
		}
		else
		{
			array = this.target.GetComponents<tk2dBaseSprite>();
			array2 = this.target.GetComponents<tk2dTextMesh>();
			array3 = this.target.GetComponents<TextMesh>();
		}
		foreach (tk2dBaseSprite tk2dBaseSprite in array)
		{
			tk2dUIColorUpDown.Tk2dColorSprite tk2dColorSprite = new tk2dUIColorUpDown.Tk2dColorSprite();
			tk2dColorSprite.tk2dSprite = tk2dBaseSprite;
			if (tk2dColorSprite.tk2dSprite.gameObject == this.target.gameObject)
			{
				tk2dColorSprite.upColor = this.UpColor;
				if (isChangeTheme)
				{
					tk2dColorSprite.tk2dSprite.color = this.UpColor;
				}
			}
			else
			{
				tk2dColorSprite.upColor = tk2dBaseSprite.color;
			}
			this.tk2dSprites.Add(tk2dColorSprite);
		}
		foreach (tk2dTextMesh tk2dTextMesh in array2)
		{
			tk2dUIColorUpDown.Tk2dColorTextMesh tk2dColorTextMesh = new tk2dUIColorUpDown.Tk2dColorTextMesh();
			tk2dColorTextMesh.tk2dTextMesh = tk2dTextMesh;
			if (tk2dColorTextMesh.tk2dTextMesh.gameObject == this.target.gameObject)
			{
				tk2dColorTextMesh.upColor = this.UpColor;
				if (isChangeTheme)
				{
					tk2dColorTextMesh.tk2dTextMesh.color = this.UpColor;
				}
			}
			else
			{
				tk2dColorTextMesh.upColor = tk2dTextMesh.color;
			}
			if (tk2dTextMesh.useGradient)
			{
				tk2dColorTextMesh.upBottomColor = tk2dTextMesh.color2;
			}
			this.tk2dTextMeshs.Add(tk2dColorTextMesh);
		}
		foreach (TextMesh textMesh in array3)
		{
			tk2dUIColorUpDown.ColorTextMesh colorTextMesh = new tk2dUIColorUpDown.ColorTextMesh();
			colorTextMesh.textMesh = textMesh;
			if (colorTextMesh.textMesh.gameObject == this.target.gameObject)
			{
				colorTextMesh.upColor = this.UpColor;
				if (isChangeTheme)
				{
					colorTextMesh.textMesh.GetComponent<Renderer>().material.color = this.UpColor;
				}
			}
			else
			{
				colorTextMesh.upColor = textMesh.color;
			}
			this.textMeshs.Add(colorTextMesh);
		}
	}

	private void OnEnable()
	{
		tk2dUIItem component = base.GetComponent<tk2dUIItem>();
		if (component != null)
		{
			component.OnDownUIItem += this.OnDown;
			component.OnUpUIItem += this.OnUp;
		}
	}

	private void OnDisable()
	{
		tk2dUIItem component = base.GetComponent<tk2dUIItem>();
		if (component != null)
		{
			component.OnDownUIItem -= this.OnDown;
			component.OnUpUIItem -= this.OnUp;
		}
	}

	private void OnDown(tk2dUIItem item)
	{
		foreach (tk2dUIColorUpDown.Tk2dColorSprite tk2dColorSprite in this.tk2dSprites)
		{
			HOTween.Kill(tk2dColorSprite.tk2dSprite);
			Color color = this.downColor * tk2dColorSprite.upColor;
			if (tk2dColorSprite.tk2dSprite.gameObject == this.target.gameObject)
			{
				color = this.downColor;
			}
			HOTween.To(tk2dColorSprite.tk2dSprite, this.tweenDuration, "color", color);
		}
		foreach (tk2dUIColorUpDown.Tk2dColorTextMesh tk2dColorTextMesh in this.tk2dTextMeshs)
		{
			HOTween.Kill(tk2dColorTextMesh.tk2dTextMesh);
			Color color2 = this.downColor * tk2dColorTextMesh.upColor;
			if (tk2dColorTextMesh.tk2dTextMesh.gameObject == this.target.gameObject)
			{
				color2 = this.downColor;
			}
			HOTween.To(tk2dColorTextMesh.tk2dTextMesh, this.tweenDuration, "color", color2);
			if (tk2dColorTextMesh.tk2dTextMesh.useGradient)
			{
				HOTween.To(tk2dColorTextMesh.tk2dTextMesh, this.tweenDuration, "color2", this.downColor * tk2dColorTextMesh.upBottomColor);
			}
		}
		foreach (tk2dUIColorUpDown.ColorTextMesh colorTextMesh in this.textMeshs)
		{
			HOTween.Kill(colorTextMesh.textMesh.GetComponent<Renderer>().material);
			Color color3 = this.downColor * colorTextMesh.upColor;
			if (colorTextMesh.textMesh.gameObject == this.target.gameObject)
			{
				color3 = this.downColor;
			}
			HOTween.To(colorTextMesh.textMesh.GetComponent<Renderer>().material, this.tweenDuration, "color", color3);
		}
	}

	private void OnUp(tk2dUIItem item)
	{
		foreach (tk2dUIColorUpDown.Tk2dColorSprite tk2dColorSprite in this.tk2dSprites)
		{
			HOTween.Kill(tk2dColorSprite.tk2dSprite);
			HOTween.To(tk2dColorSprite.tk2dSprite, this.tweenDuration, "color", tk2dColorSprite.upColor);
		}
		foreach (tk2dUIColorUpDown.Tk2dColorTextMesh tk2dColorTextMesh in this.tk2dTextMeshs)
		{
			HOTween.Kill(tk2dColorTextMesh.tk2dTextMesh);
			HOTween.To(tk2dColorTextMesh.tk2dTextMesh, this.tweenDuration, "color", tk2dColorTextMesh.upColor);
			if (tk2dColorTextMesh.tk2dTextMesh.useGradient)
			{
				HOTween.To(tk2dColorTextMesh.tk2dTextMesh, this.tweenDuration, "color2", tk2dColorTextMesh.upBottomColor);
			}
		}
		foreach (tk2dUIColorUpDown.ColorTextMesh colorTextMesh in this.textMeshs)
		{
			HOTween.Kill(colorTextMesh.textMesh.GetComponent<Renderer>().material);
			HOTween.To(colorTextMesh.textMesh.GetComponent<Renderer>().material, this.tweenDuration, "color", colorTextMesh.upColor);
		}
	}

	private GameObject target;

	public tk2dBaseSprite buttonSprite;

	public bool isChildTween;

	public float tweenDuration = 0.2f;

	public Color upColor = Color.white;

	public Color downColor = Color.white;

	private List<tk2dUIColorUpDown.Tk2dColorSprite> tk2dSprites = new List<tk2dUIColorUpDown.Tk2dColorSprite>();

	private List<tk2dUIColorUpDown.Tk2dColorTextMesh> tk2dTextMeshs = new List<tk2dUIColorUpDown.Tk2dColorTextMesh>();

	private List<tk2dUIColorUpDown.ColorTextMesh> textMeshs = new List<tk2dUIColorUpDown.ColorTextMesh>();

	private class Tk2dColorSprite
	{
		public tk2dBaseSprite tk2dSprite;

		public Color upColor = Color.white;
	}

	private class Tk2dColorTextMesh
	{
		public tk2dTextMesh tk2dTextMesh;

		public Color upColor = Color.white;

		public Color upBottomColor = Color.white;
	}

	private class ColorTextMesh
	{
		public TextMesh textMesh;

		public Color upColor = Color.white;
	}
}
